<?php
include_once("../service/ServiceEnum.php"); 
include_once("Controller.php");
//继承抽象类Controller和接口IController
class ControllerEnum extends Controller implements IController 
{
  //暂时废弃
  public function handleAction()
  {
    throw new Exception("尚未实现");
  }
  //查询,根据枚举表中的pid查询
  public function query()
  {
    $id=is_null($_GET['pid'])?"-2":$_GET['pid'];
    (new ServiceEnum())->getByPid($id);
  }
  /**
   *add a new enum
   */
  public function addRec()
  {
    //$ob = json_decode($_POST);
    if(is_null($_POST['strpid']))
    {
      echo "error";
      return;
    }
    else
    $strpid = is_null($_POST['strpid'])?"":$_POST['strpid'];
    //$streid = is_null($_POST['streid'])?"":$_POST['streid'];
    $strname = is_null($_POST['strname'])?"":$_POST['strname'];
    $strvalue = is_null($_POST['strvalue'])?"":$_POST['strvalue'];
    //send the result
    echo (new ServiceEnum())->create(array($strpid,$strname,$strvalue));
  }
  public function delRec()
  { 
    $strpid = is_null($_POST['strpid'])?"":$_POST['strpid'];
    $streid = is_null($_POST['streid'])?"":$_POST['streid'];
    echo (new ServiceEnum())->delete($strpid,$streid);
  }
  public function editRec()
  {
    $strpid = is_null($_POST['strpid'])?"":$_POST['strpid'];
    $streid = is_null($_POST['streid'])?"":$_POST['streid'];
    $strname = is_null($_POST['strname'])?"":$_POST['strname'];
    $strvalue = is_null($_POST['strvalue'])?"":$_POST['strvalue'];
    echo (new ServiceEnum())->update(array($strname,$strvalue,$strpid,$streid));
    //echo json_encode(array("strvalue"=>$strvalue,"strpid"=>$strpid));
  }
} 
 ?>